package com.koron.order.config;

import com.landray.kmss.yggs.todonotify.WebServiceClient;
import com.landray.kmss.yggs.todonotify.WebServiceConfig;
import com.landray.kmss.yggs.todonotify.webservice.IYggsTodonotifyTodoWebServiceService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

/**
 * @ClassName WebConfig
 * @description
 * @Author zhouj
 * @Date 2021/5/8 10:21
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    //@Value("${app.version}")
    private String url;

    /**
     * 解决swagger被拦截的问题
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        registry.addResourceHandler("/temp/**")
                .addResourceLocations("file:"+ System.getProperty("user.dir") +"/temp/");

    }

    @Bean
    public IYggsTodonotifyTodoWebServiceService iYggsTodonotifyTodoWebServiceService(WebServiceConfig cfg) throws Exception {
        //WebServiceConfig cfg = WebServiceConfig.getInstance();
        return (IYggsTodonotifyTodoWebServiceService) WebServiceClient.callService(cfg.getAddress(), cfg.getServiceClass());
    }

    /**
     * 注入一个ServerEndpointExporter,
     * 该Bean会自动注册使用@ServerEndpoint注解申明的websocket endpoint
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

}
